// pages/page10020/page10020.js
var appInstance = getApp();
Page({
  data:{
    focus:false,
    tellogin:false,
    telnum:'',
    telche:''
  },
  onLoad:function(options){
    var tel = options.tel;
    this.setData({
      telnum:tel
    })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  setphone:function(e){
    var telnum = e.detail.value;
    this.setData({
      telnum:telnum
    })
  },
  setcheck:function(e){
    console.log(e);
    var telche = e.detail.value;
    this.setData({
      telche:telche
    })
  },
  getcheck: function() {
    var telnum = this.data.telnum;
    var that = this;
    console.log(telnum.length)
    if(telnum.length!=11){
      appInstance.showModal({
        content: '请输入11位手机号'
       });
      return false
      };
    var param = appInstance.globalData.session_key;
    var searchPrdList ={
      token :param.myXcxSessionId,
      source:'1', 
      mobileNo:telnum 
    }
    appInstance.sendRequest({
      url:'/regValidate/sendValidateMsgXCX',
      data:searchPrdList,
      method:'POST',
      success: function(res){
        that.setData({
          focus: true
          })
       appInstance.showToast({
             title: '发送成功',
              icon: 'success'
          })
      },
      fail: function(res){
        console.log('getmode fail');
      },
      complete: function(res){
      }
    }) 
  },
  tellogin:function(){
     var that = this;
    var param = appInstance.globalData.session_key;
    var telnum = this.data.telnum;
    var checknum = this.data.telche;
    var searchPrdList ={
      token :param.myXcxSessionId,
      source:'1', 
      validateCode:checknum,
      mobileNo:telnum
    }
    appInstance.sendRequest({
      url:'/regValidate/checkSMSValidCodeXCX',
      data:searchPrdList,
      method:'POST',
      success: function(res){
        if(res.result==0){
          appInstance.showToast({
             title: '绑定成功',
              icon: 'success'
          })
          wx.navigateBack({
            delta: 1, // 回退前 delta(默认为1) 页面
            success: function(res){
              // success
            },       
          })
        }else{
           appInstance.showToast({
             title: res.msg,
             icon:'loading',
             duration:2000
          })
        }
      },
      fail: function(res){
        console.log('getmode fail');
      },
      complete: function(res){
      }
    }) 
  },
  getTopage:function(e){
    console.log(e);
    var param = e.currentTarget.dataset.op;
     param = '../'+param+'/'+param
    wx.navigateTo({
      url: param,
      success: function(res){
        // success
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  }
})